package com.education.controller;

import com.education.domain.Tbscore;
import com.education.domain.TbscorePlus;
import com.education.service.ScoreService;
import com.education.service.TermService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by zhangjiawen on 2019/11/19.
 */
@Controller
@RequestMapping("/score")
public class ScoreController {
    Logger logger= LoggerFactory.getLogger(this.getClass());
    @Autowired
    private ScoreService scoreService;
    @Autowired
    private TermService termService;

    @RequestMapping("/selectByExample")
    public Object selectByExample(int lcourseId,ModelMap mm) {
        TbscorePlus tbscorePlus=new TbscorePlus();
        tbscorePlus.setLcourseid(lcourseId);

        mm.put("scoreObj",scoreService.getByCondition(tbscorePlus));
        return "score/score";

    }

    /**
     * 查询补充所有条件
     * @return
     */
    @ResponseBody
    @RequestMapping("/getByCondition")
    public Object getAllCondition(@RequestBody Map map) {
        if(map.size()==0){
            return null;
        }
        TbscorePlus tbscorePlus=new TbscorePlus();
        int count=0;
        if(map.get("lTermId")!=null){
            tbscorePlus.setLtermid(Integer.parseInt((String) map.get("lTermId")));
            count++;
        }
        if(map.get("lClassId")!=null){
            tbscorePlus.setLclassid(Integer.parseInt((String) map.get("lClassId")));
            count++;
        }
        if(map.get("lCourseId")!=null){
            if(Integer.parseInt((String) map.get("lCourseId"))==0){
                //TODO 查询所有科目总成绩
            }else{
                tbscorePlus.setLcourseid(Integer.parseInt((String) map.get("lCourseId")));
            }
            count++;
        }
        if(map.get("lTestId")!=null){
            tbscorePlus.setLtestid(Integer.parseInt((String) map.get("lTestId")));
            count++;
        }
        if(count<4){
            return null;
        }

        return scoreService.getByCondition(tbscorePlus);

    }





}
